package com.chen.shopping_manager_api.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.shopping_common.pojo.Permission;
import com.chen.shopping_common.result.BaseResult;
import com.chen.shopping_common.service.PermissionService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/permission")
public class PermissionController {

    @DubboReference
    private PermissionService permissionService;

    @PostMapping("/add")
    public BaseResult addPermission(@RequestBody Permission permission){
        permissionService.addPermission(permission);
        return BaseResult.ok();
    }

    @PutMapping("/update")
    public BaseResult updatePermission(@RequestBody Permission permission){
        permissionService.updatePermission(permission);
        return BaseResult.ok();
    }

    @DeleteMapping("/delete")
    public BaseResult deletePermission(Long pid){
        permissionService.deletePermission(pid);
        return BaseResult.ok();
    }

    @GetMapping("/findById")
    public BaseResult findPermissionById(Long pid){
        Permission permissionById = permissionService.findPermissionById(pid);
        return BaseResult.ok(permissionById);
    }

    @GetMapping("/findAll")
    public BaseResult findAllPermission(){
        List<Permission> permissionAll = permissionService.findPermissionAll();
        return BaseResult.ok(permissionAll);
    }

    @GetMapping("/search")
    public BaseResult findPermissionByPage(int page,int size){
        Page<Permission> permissionByPage = permissionService.findPermissionByPage(page, size);
        return BaseResult.ok(permissionByPage);
    }
}
